package com.hc.sort.manager;

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;

import com.hc.sort.server.dao.AdminDao;
import com.hc.sort.server.dao.AdminDaoImpl;
import com.hc.sort.server.pojo.Admin;
import com.hc.sort.server.service.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.List;

public class ManagerLoginUI extends JFrame {
	AdminService adminService = new AdminServiceImpl();
	private JPanel contentPane;
	private JTextField textName;
	private JPasswordField textPwd;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ManagerLoginUI frame = new ManagerLoginUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ManagerLoginUI() {
		setTitle("管理员登录界面");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 473, 335);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("用户名：");
		lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 16));
		lblNewLabel.setBounds(76, 53, 64, 26);
		contentPane.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("密  码：");
		lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 16));
		lblNewLabel_1.setBounds(76, 125, 64, 26);
		contentPane.add(lblNewLabel_1);
		
		textName = new JTextField();
		textName.setBounds(150, 55, 202, 25);
		contentPane.add(textName);
		textName.setColumns(10);
		
		JButton btnLogin = new JButton("登  录");
		btnLogin.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//获取文本框里的用户名和密码
				String userName=textName.getText();
				String pwd=textPwd.getText();
				
				//验证登录
				if (!"".equals(userName) && !"".equals(pwd)) {
					AdminDao adminDao=new AdminDaoImpl();
					Admin admin=adminDao.LoginAdmin(userName, pwd);
					if (admin!=null) {
						JOptionPane.showMessageDialog(null, "登录成功！");
						ManagerUI managerUI=new ManagerUI(userName);
						managerUI.setVisible(true);
						ManagerLoginUI.this.dispose();
					}else {
						JOptionPane.showMessageDialog(null, "登录失败，用户名或密码不正确！");
					}
					
				}else {
					JOptionPane.showMessageDialog(null, "用户名或密码不能为空,请重新输入！");
				}
			}
		});
		btnLogin.setFont(new Font("宋体", Font.PLAIN, 16));
		btnLogin.setBounds(76, 219,99, 26);
		contentPane.add(btnLogin);
		
		JButton btnCancel = new JButton("取  消");
		btnCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//退出系统
				System.exit(0);
			}
		});
		btnCancel.setFont(new Font("宋体", Font.PLAIN, 16));
		btnCancel.setBounds(261, 219, 91, 26);
		contentPane.add(btnCancel);
		
		textPwd = new JPasswordField();
		textPwd.setBounds(150, 129, 202, 21);
		contentPane.add(textPwd);
	}
}
